//
//  InputPassWordView.m
//  lhpc_manager
//
//  Created by 李英杰 on 2017/9/6.
//  Copyright © 2017年 zhaoyongjie. All rights reserved.
//

#import "InputPassWordView.h"

@interface InputPassWordView ()<UITextFieldDelegate>

@property (nonatomic, strong) UIView * backView;
@property (nonatomic, strong) UILabel * titleLabel;


@end

@implementation InputPassWordView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = [UIColor whiteColor];
        [self setMainView];
    }
    return self;
}


-(void)setTitleStr:(NSString *)titleStr{
    
    self.titleLabel.text = titleStr;
}

-(void)setPlaceholderStr:(NSString *)placeholderStr{
    self.passwordTextField.placeholder = placeholderStr;
}

-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
    if(textField.text.length > 5 && string.length > 0){
        return NO;
    }
    return YES;
}


-(void)setMainView{
    
    [self addSubview:self.backView];
    [self.backView addSubview:self.titleLabel];
    [self.backView addSubview:self.passwordTextField];
    
}

-(void)updateConstraints{
    [super updateConstraints];
    
    [self.backView mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.edges.equalTo(self);
        
    }];
    
    [self.titleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.left.equalTo(self.backView).offset(10);
        make.centerY.equalTo(self.backView);
        
    }];
    
    [self.passwordTextField mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.top.right.bottom.equalTo(self.backView);
        make.left.equalTo(self.titleLabel.mas_right).offset(20);

        
    }];
    
}


-(UIView *)backView{
    if (!_backView) {
        _backView = [[UIView alloc]init];
        _backView.backgroundColor = [UIColor whiteColor];
    }
    return _backView;
}

-(UILabel *)titleLabel{
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc]init];
        _titleLabel.font = [UIFont systemFontOfSize:16];
        _titleLabel.textAlignment = NSTextAlignmentLeft;
        _titleLabel.textColor = BLACKCOLOR;
        
    }
    return _titleLabel;
}

-(UITextField *)passwordTextField{
    if (!_passwordTextField) {
        _passwordTextField = [[UITextField alloc]init];
        _passwordTextField.delegate = self;
        _passwordTextField.returnKeyType = UIReturnKeyDone;
        _passwordTextField.keyboardType = UIKeyboardTypeNumberPad;
        _passwordTextField.secureTextEntry = YES;

    }
    return _passwordTextField;
}

@end
